package org.mic.swagger;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
@FeignScan
@ConditionalOnProperty(prefix = "swagger", name = "swagger-open", havingValue = "true")
public class Swagger2Config {

    private String title = "网关总服务";

    @Bean
    public Docket agentDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title(title)    //接口文档大标题
                        .description("测试接口服务")    //接口文档描述
                        .version("v1")   //版本号
                        .build())
                .pathMapping("/test")       //最终url前缀（feign的name属性）
                .select()
                .apis(RequestHandlerSelectors.basePackage("org.mc.api.test"))  //要扫描的包()
                .paths(PathSelectors.any())      //此处可以添加过滤器
                .build()
                .groupName("测试");            //分组名称
    }

    @Bean
    public Docket bespeakDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title(title)    //接口文档大标题
                        .description("用户接口服务")    //接口文档描述
                        .version("v1")   //版本号
                        .build())
                .pathMapping("/user")       //最终url前缀（feign的name属性）
                .select()
                .apis(RequestHandlerSelectors.basePackage("org.mc.api.user"))  //要扫描的包()
                .paths(PathSelectors.any())      //此处可以添加过滤器
                .build()
                .groupName("用户");            //分组名称
    }

}
